home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / SYS / s / sc.wrx < prev    next >
Text File  |  1996-09-26  |  8KB  |  321 lines

  1. /* ARexx script for WRITE and SC_SCMSG communication */
  2.  
  3. /*
  4.  * written 20/09/1993 by Lars Hanke
  5.  * © 1993 by MGR-Software, Asgrad
  6.  * contact: mgr@asgard.bo.open.de
  7.  *
  8.  * Installation:
  9.  *    - set the 'helppath' variable following this comment to where your
  10.  *      SAS/C AmigaGuide files can be found. By default they are installed
  11.  *      to SC:Help/
  12.  *
  13.  *    - set the SCMSG tool's defaults by calling "SCMSG", Project menu,
  14.  *      "Set options" to:
  15.  *         Hidden
  16.  *         NoRexxOnly     - isn't supported by SCMSG otherwise
  17.  *         NoAutoEdit
  18.  *
  19.  *         PortName: ""
  20.  *      EditCommand: "rx sc.wrx init"
  21.  *         GotoFile: ""
  22.  *         GoToLine: ""
  23.  *
  24.  *      click "Use" and select "Save options" in the Project menu.
  25.  *
  26.  *    - add the following lines to your WRITE configuration file
  27.  *
  28.  *         /* SC support controls */
  29.  *
  30.  *         KEY "numpad control 2"       DoRexx "sc.wrx next" 1;
  31.  *         KEY "numpad control 8"       DoRexx "sc.wrx last" 1;
  32.  *         KEY "numpad control 7"       DoRexx "sc.wrx begin" 1;
  33.  *         KEY "numpad control 1"       DoRexx "sc.wrx end" 1;
  34.  *         KEY "numpad control enter"   DoRexx "sc.wrx correct" 1;
  35.  *         KEY "numpad alt     7"       DoRexx "sc.wrx build" 1;
  36.  *         KEY "numpad alt     1"       DoRexx "sc.wrx done" 1;
  37.  *         KEY "numpad control 5"       DoRexx "sc.wrx index" 1;
  38.  *
  39.  *
  40.  *    - compile your programs using the 'errrexx' compiler option for SC
  41.  *
  42.  * Operation:
  43.  *   As you probably have noted all operation hotkeys are situated on
  44.  *   the numeric keypad and qualified by control. As this is the way
  45.  *   of LSE's navigation functions you should be able to keep it in
  46.  *   mind easily:
  47.  *
  48.  *      Up: (8)   - goto previous message
  49.  *    Down: (2)   - goto next message
  50.  *    Home: (7)   - goto first message
  51.  *     End: (1)   - goto last message
  52.  *   Enter:       - remove current message and goto next one
  53.  *  Center: (5)   - display Guide page for message
  54.  *
  55.  *   The above commands move to the beginning of the line that caused the
  56.  *   error. New files are loaded automatically, if necessary. A security
  57.  *   request is done, if the current file was changed. The errormessage
  58.  *   is displayed in a standard text requester. Main control is qualified
  59.  *   with alt:
  60.  *
  61.  *          Home: - rebuild the current project
  62.  *           End: - quit the SCMSG program
  63.  *
  64.  *   From the above configuration example operation and the meaning of
  65.  *   the argument 'action' should be clear.
  66.  *
  67.  *   When the SCMSG window pops up, doubleclick any message you want to
  68.  *   start (or later go on) with
  69.  *
  70.  */
  71.  
  72. helppath = "XDOC:guides/help/"
  73.  
  74. ARG action
  75.  
  76. IF ~show('P',"SC_SCMSG") THEN
  77. DO
  78.   if (action = "INIT") then say "You should not invoke me manually!"
  79.   else do
  80.      if show('P',"WRITE") then
  81.      do
  82.         address 'WRITE'
  83.         'MessageOK (No SCMSG ARexx-server running)'
  84.         exit 0
  85.      end
  86.      else say "You should not invoke me manually!"
  87.   end
  88. END
  89.  
  90. IF ~show('P',"WRITE")
  91. THEN DO
  92.   if action = "INIT" then
  93.   do
  94.      ADDRESS "COMMAND"
  95.      "run >NIL: <NIL: dh0:Text/WRITE"
  96.      "WB:REXXC/WaitForPort <NIL: >NIL: WRITE"
  97.   end
  98.   else do
  99.      say 'call me with the "Init" option first'
  100.      exit 5
  101.   end
  102. END
  103.  
  104. IF action = "QUIT" then
  105. do
  106.   address "SC_SCMSG"
  107.   'quit'
  108.   exit 0
  109. end
  110.  
  111. options results
  112.  
  113. Port = getclip('SC_WRITE_PORT')
  114. ID = getclip('SC_WRITE_ID')
  115.  
  116. if action = "INIT" then
  117. do
  118.   address 'WRITE'
  119.   if ((Port == "") | ~show('P',Port)) then
  120.   do
  121.     'NEWED ""'
  122.     ID = RESULT
  123.     if ~setclip('SC_WRITE_ID',ID) then
  124.     do
  125.        "MessageOK (Kann kein ID Clipboard bekommen!)"
  126.        exit 20
  127.     end
  128.     OPENPORT ID
  129.     Port = RESULT
  130.     IF Port="" THEN DO
  131.        "MessageOK (Es konnte kein Port für SAS/C geöffnet werden)"
  132.        exit 20
  133.     end
  134.     if ~setclip('SC_WRITE_PORT',Port) then
  135.     do
  136.        "MessageOK (Kann kein Port Clipboard bekommen!\nBitte schliessen Sie das Fenster)"
  137.        WaitPort ID
  138.        exit 20
  139.     end
  140.     call setclip('SC_WRITE_WINDOW',0)
  141.   end
  142. end
  143. else do
  144.   if Port = "" then
  145.   do
  146.      address 'WRITE'
  147.      'MessageOK (Call me with the "Init" option first)'
  148.      exit 0
  149.   end
  150.   else if ~show('P',Port) then
  151.   do
  152.      address 'WRITE'
  153.      'MessageOK (The current window is not the master)'
  154.      exit 0
  155.   end
  156. end
  157.  
  158. if action ~= "INIT" then
  159. do
  160.   address 'SC_SCMSG'
  161.   select
  162.      when action = "NEXT" then 'next'
  163.      when action = "LAST" then 'prev'
  164.      when action = "BEGIN" then 'top'
  165.      when action = "END" then 'bottom'
  166.      when action = "CORRECT" then 'delete'
  167.      when action = "SELECT" then
  168.         do
  169.            'show activate'
  170.            exit 0
  171.         end
  172.      when action = "DONE" then 'quit'
  173.      when action = "BUILD" then 'build'
  174.      when action = "INDEX" then
  175.         do
  176.            'errnum'
  177.            num = RESULT
  178.            if num ~= "" then
  179.            do
  180.               num = right(num,3,'0')
  181.  
  182.               address 'COMMAND'
  183.               'run >nil: amigaguide' helppath||'scmsg.guide doc scm'||num
  184.               exit 0
  185.            end
  186.         end
  187.      otherwise action = "UNDEF"
  188.   end
  189. end
  190.  
  191. INTERPRET ADDRESS Port
  192.  
  193. select
  194.   when action = "DONE" then msg="SCMSG terminated"
  195.   when action = "BUILD" then msg="Rebuilding ..."
  196.   when action = "UNDEF" then msg="REXX-Error: undefined action code"
  197.   otherwise msg=""
  198. end
  199.  
  200. if msg ~= "" then
  201. do
  202.   'MessageOK "'||msg||'"'
  203.   exit 0
  204. end
  205.  
  206. 'GETVAR (_WinMode)'
  207. if( RESULT ~= 0 ) then
  208. do
  209.   if getclip('SC_WRITE_WINDOW') == 1 then 'WINDOW 0 0 0 0'
  210.   else do
  211.      WINDOWSIZE = "0 0 0 0"
  212.      IF Open(File,"ENV:"||WRITESIZE,r) THEN
  213.      DO
  214.        WINDOWSIZE = ReadLn(File);
  215.        call Close(File)
  216.      END
  217.      'Window' WINDOWSIZE
  218.      call setclip('SC_WRITE_WINDOW',1);
  219.   end
  220. end
  221.  
  222. 'GETVAR (_FILENAME)'
  223. cfile = RESULT
  224.  
  225. address 'SC_SCMSG'
  226. 'FILE'
  227. nfile = RESULT
  228.  
  229. 'errnum'
  230. if RESULT = "" then
  231. do
  232.   'quit'
  233.   INTERPRET ADDRESS Port
  234.   'MessageOK (All errors corrected!)'
  235.   call setclip('SC_WRITE_PORT',"")
  236.   call setclip('SC_WRITE_ID',"")
  237.   exit(0)
  238. end
  239.  
  240. if (cfile ~= nfile) then
  241. do
  242.   INTERPRET ADDRESS Port
  243.  
  244.   'GETVAR (_Changed)'
  245.   if( RESULT = 1 ) then
  246.   do
  247.      'ASK "Your current file was changed!\nSave it?" "_Forget ^|_Save *"'
  248.      'GETVAR (_RN)'
  249.      if (RESULT ~= 0) then 'Save "'||cfile||'" {}'
  250.   end
  251.   'Open "'||nfile||'"'
  252.   address 'SC_SCMSG'
  253. end
  254.  
  255. 'line'
  256. line = RESULT
  257. 'text'
  258. msg = RESULT
  259. 'class'
  260. class = RESULT
  261.  
  262. INTERPRET ADDRESS Port
  263. 'GOTO 1' line
  264. txt = debrace(class||':' msg)
  265. "MessageOK ("||txt||")"
  266.  
  267. exit 0
  268.  
  269. debrace: procedure                          /* remove braces from texts */
  270.  
  271.   parse arg line
  272.  
  273.   do until p = 0                            /* replace parenthesa by braces, */
  274.      p = pos('(',line)                      /* because we use the former as  */
  275.      if p ~= 0 then                         /* quotes for WRITE itself.      */
  276.      do
  277.         line = delstr(line,p,1)
  278.         line = insert('{',line,p-1)
  279.      end
  280.   end
  281.  
  282.   do until p = 0
  283.      p = pos(')',line)
  284.      if p ~= 0 then
  285.      do
  286.         line = delstr(line,p,1)
  287.         line = insert('}',line,p-1)
  288.      end
  289.   end
  290.  
  291.   p = pos('"',line)                         /* replace " by ', for we also  */
  292.   do while p ~= 0                           /* need outer quotes            */
  293.      line = delstr(line,p,1)
  294.      line = insert("'",line,p-1)
  295.      p = pos('"',line)
  296.   end
  297.  
  298.   line = strip(line)
  299.   if length(line) > 230 then
  300.      line = left(line,230)                  /* we may only pass 255 chars a time */
  301.  
  302.   'GetVar (_WinWidth)'                      /* insert \n to stay in window */
  303.   width = RESULT
  304.   width = width-trunc(0.2*width)
  305.   l = length(line)
  306.   p = 1
  307.   do while l > width
  308.      p = p+width
  309.      s = left(line,p)
  310.      r = words(s)
  311.      i = wordindex(line,r)
  312.      line = insert("\n",line,i)
  313.      p = p+2
  314.      l = length(line) - (i+2);
  315.   end
  316.  
  317.   return line
  318.  
  319.  
  320.  
  321.